using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using jSLCore.Service.Data;
using jSLCore.Service.Workflow.Linq;

namespace jSLCore.Service.Security
{
    partial class Role : BaseData
    {
        [DataMember]
        public PermissionDescription[] PermissionCash { get; set; }

        [DataMember]
        public Role[] BaseRoles { get; set; }

        public void BeforeSending(SecurityDatabaseDataContext db)
        {
            var permissionCash = new List<PermissionDescription>(Permissions.Count);
            permissionCash.AddRange(Permissions.Select(permission => db.PermissionDescriptions.GetOne(permission.PermissionNumber, "Permission")));

            PermissionCash = permissionCash.ToArray();


            var baseRoles = new List<Role>(RoleInherits1.Count);
            baseRoles.AddRange(RoleInherits1.Select(baseRole => baseRole.ParentRole));

            BaseRoles = baseRoles.ToArray();
        }
    }

    partial class SecurityDatabaseDataContext
    {
    }
}